﻿using System;
using System.Collections.Generic;
using System.Linq;
using VideoSeller.Business.Data.Entities;

namespace VideoSeller.Business.Models
{
	public class StatisticModel
	{
		private readonly CategoryModel _categoryModel;
		private readonly OnlineContentModel _onlineContentModel;
        private readonly PostingModel _postingModel;

		public StatisticModel(CategoryModel categoryModel, OnlineContentModel onlineContentModel, PostingModel postingModel)
		{
			_categoryModel = categoryModel;
			_onlineContentModel = onlineContentModel;
            _postingModel = postingModel;
		}

		public List<StatisticOnlineItem> GetOnlineStatistic()
		{
			var result =_categoryModel.GetAll()
				              .Select(x => new StatisticOnlineItem {Category = x, Registered = _onlineContentModel.GetOnlineCount(x.Id)})
				              .ToList();
			return result;
		}
      
		public List<StatisticOnlineItem> GetOnlineStatistic(DateTime start, DateTime end)
		{
			var result = _categoryModel.GetAll().Select(x => new StatisticOnlineItem { Category = x, Anonymous = 2, Registered = 8 }).ToList();

			//return _dataContext.Persons.Join(_dataContext.BusinessTrips, person => person.Id, trip => trip.PersonId,
			//					 (person, trip) => new { Person = person, Trip = trip })
			//	   .Where(personTrip => personTrip.Trip.StartDate <= startDate && personTrip.Trip.EndDate >= endDate)
			//	   .Join(_dataContext.Cities, personTrip => personTrip.Trip.CityId, city => city.Id,
			//			 (personTrip, city) => new { Person = personTrip.Person, City = city })
			//	   .Where(personCity => personCity.City.Name.ToLower() == "москва")
			//	   .Select(personCity => personCity.Person)
			//	   .AsEnumerable();

			return result;
		}
        public void GetVSMByPeriod(DateTime start, DateTime end)
        {
            
        }
	}
}